package com.example.demo.controller;

import com.example.demo.pojo.*;
import com.example.demo.service.MovieService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @创建人: ZS
 * @创建时间: 2021/4/2
 * @描述:
 */
//@RestController注解,相当于@Controller+@ResponseBody两个注解的结合，返回json数据不需要在方法前面加@ResponseBody注解了，但使用@RestController这个注解，就不能返回jsp,html页面，视图解析器无法解析jsp,html页面
@RestController
//跨域
@CrossOrigin
//在Spring MVC 中使用 @RequestMapping 来映射请求，也就是通过它来指定控制器可以处理哪些URL请求，相当于Servlet中在web.xml中配置的映射作用一致
@RequestMapping("/maoyan")
public class MovieController {
//    @Autowired 注释，它可以对类成员变量、方法及构造函数进行标注，完成自动装配的工作。 通过 @Autowired的使用来消除 set ，get方法
    @Autowired
    MovieService movieService;

    @RequestMapping("/moviesry")
    public List<Movie> findAllRy(){return movieService.findAllRy();}
    @RequestMapping("/moviessy")
    public List<Movie> findAllSy(){return movieService.findAllSy();}
    @RequestMapping("/moviesyp")
    public List<Movie> findAllYp(){return movieService.findAllYp();}
//    @RequestMapping("/moviesallimg")
//    public List<MovieImg> findAllImg(){return movieService.findAllImg();}
    @RequestMapping("/moviesproduct")
    public List<Product> findAllProduct(){return movieService.findAllProduct();}
    @RequestMapping("/movieslists")
    public List<Lists> findAllLists(){return movieService.findAllLists();}
    @RequestMapping("/moviesimgs")
    public List<HeaderImg> findImg(){return movieService.findImg();}
    @RequestMapping("/moviesrys")
    public Map getMoviesRyArray(int page) {
        Page pager = movieService.getRyPage(page);
        Map ry = new HashMap();
        ry.put("pageMax",pager.getPageMax());
        ry.put("page",pager.getPage());
        ry.put("row",pager.getRow());
        ry.put("list",movieService.queryMoviesRy(page));
        return ry;
    }
    @RequestMapping("/moviessys")
    public Map getMoviesSyArray(int page) {
        Page pages = movieService.getSyPage(page);
        Map sy = new HashMap();
        sy.put("pageMax",pages.getPageMax());
        sy.put("page",pages.getPage());
        sy.put("row",pages.getRow());
        sy.put("list",movieService.queryMoviesSy(page));
        return sy;
    }
    @RequestMapping("/moviesyps")
    public Map getMoviesYpArray(int page) {
        Page pagey = movieService.getYpPage(page);
        Map yp = new HashMap();
        yp.put("pageMax",pagey.getPageMax());
        yp.put("page",pagey.getPage());
        yp.put("row",pagey.getRow());
        yp.put("list",movieService.queryMoviesYp(page));
        return yp;
    }
    @RequestMapping("/movies")
    public List<Movie> findMovies(int office,int id){
        if (office==1){
            return movieService.findMovieRy(id);
        }else if (office==2){
            return movieService.findMovieSy(id);
        }else if (office==3){
            return movieService.findMovieYp(id);
        }else {
            return movieService.findMovie(id);
        }
    }
    @RequestMapping("/movie")
    public List<Movie> searchMovie(String name){
        return movieService.searchMovie(name);
    }
}